import { createApp, h, InjectionKey } from "vue";
import App from "./App.vue";
import { createStore } from "vuex";
import router from "./router/index";
import "tailwindcss/tailwind.css";
import store from "./store";
import { createPinia } from "pinia";

let app = createApp(App);
app.use(router);
app.use(store);
app.use(createPinia());

app.component("comp", {
  render: function () {
    return h("div", {}, ["as"]);
  },
});
router.isReady().then(() => {
  app.mount("#app");
});
const modules = import.meta.glob("./components/*.vue");
for (const path in modules) {
  modules[path]().then((mod) => {
    console.log(path, mod, "all");
  });
}

const modules1 = import.meta.globEager("./components/*.vue");
console.log(modules1, "aa"); //require.content =>importAll 是函数也是对象 接收一个路径返回一个资源

class Control {
  protected state: any;
  constructor(state: any) {
    console.log(state);
    this.state = state;
  }
  print() {
    console.log("这是Control类的打印操作");
    console.log(this.state, "打印Control的私有属性state");
  }
}
const control = new Control(false);
control.print();

interface SelectableControl extends Control {
  // [propName:string]:any
  select(): void;
}

class Button extends Control implements SelectableControl {
  constructor(state: any) {
    super(state);
  }
  select() {
    console.log("这是Button类的操作");
  }
}
const button = new Button("button");
// console.log(button.state);
button.select();
button.print();

function Path(path: string) {
  return function (target: Function) {
    !target.prototype.$Meta && (target.prototype.$Meta = {});
    target.prototype.$Meta.baseUrl = path;
  };
}

@Path("/hello")
class HelloService {
  constructor() {}
}

console.log(HelloService.prototype.$Meta); // 输出：{ baseUrl: '/hello' }
let hello = new HelloService();
console.log(hello.$Meta); // 输出：{ baseUrl: '/hello' }

function GET(url: string) {
  return function (target, methodName: string, descriptor: PropertyDescriptor) {
    !target.$Meta && (target.$Meta = {});
    target.$Meta[methodName] = url;
  };
}

class HelloService1 {
  constructor() {}
  @GET("xx")
  getUser() {}
}

console.log((<any>HelloService1).$Meta);

function PathParam(paramName: string) {
  return function (target, methodName: string, paramIndex: number) {
    !target.$Meta && (target.$Meta = {});
    target.$Meta[paramIndex] = paramName;
  };
}

class HelloService2 {
  constructor() {}
  getUser(@PathParam("userId") userId: string) {}
}

console.log((<any>HelloService2).prototype.$Meta); // {'0':'userId'}

function DefaultValue(value: string) {
  return function (target: any, propertyName: string) {
    target[propertyName] = value;
  };
}

class Hello {
  @DefaultValue("world") greeting: string;
}

console.log(new Hello().greeting); // 输出: world

function ClassDecorator() {
  return function (target) {
    console.log("I am class decorator");
  };
}
function MethodDecorator() {
  return function (target, methodName: string, descriptor: PropertyDescriptor) {
    console.log("I am method decorator");
  };
}
function Param1Decorator() {
  return function (target, methodName: string, paramIndex: number) {
    console.log("I am parameter1 decorator");
  };
}
function Param2Decorator() {
  return function (target, methodName: string, paramIndex: number) {
    console.log("I am parameter2 decorator");
  };
}
function PropertyDecorator(str: string) {
  return function (target: any, propertyName: string) {
    target.greeting1 = str;
  };
}

@ClassDecorator()
class Hello1 {
  @PropertyDecorator("xxxx112312")
  public greeting1: string = "1";

  get greeting() {
    return this.greeting1;
  }

  @MethodDecorator()
  greet(@Param1Decorator() p1: string, @Param2Decorator() p2: string) {}
}
let a = new Hello1();
console.log(a);
